package vn.vfriends.games.service.impl;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.handler.MessageContext;
import vn.vfriends.games.service.UserService;
import vn.vfriends.id.ws.User;
import vn.vfriends.id.ws.UserWS;
import vn.vfriends.id.ws.UserWS_Service;

/**
 *
 * @author tuan@vfriends.vn
 */
public class UserServiceImpl implements UserService {

    private UserWS getUserWS() throws Exception {
        UserWS_Service service = new UserWS_Service();
        UserWS userWS = service.getUserWSPort();
        Map<String, Object> requestContext = ((BindingProvider)userWS).getRequestContext();
        
        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        headers.put("USERNAME", Collections.singletonList("wsuser"));
        headers.put("PASSWORD", Collections.singletonList("wsuser"));
        requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
        return userWS;
    }
    
    @Override
    public User findUserByUsername(String username) throws Exception {
        return this.getUserWS().findUserByUsername(username);
    }

    @Override
    public User findUserByEmail(String email) throws Exception {
        return this.getUserWS().findUserByEmail(email);
    }

    @Override
    public User createCustomer(String email, String fullName) throws Exception {
        return this.getUserWS().createCustomer(email, fullName);
    }

}
